package product_type

import (
	"context"
	"gitee.com/zyw0605688_admin/gozero/product_service/model"

	"gitee.com/zyw0605688_admin/gozero/product_service/internal/svc"
	"gitee.com/zyw0605688_admin/gozero/product_service/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductTypeDeleteLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductTypeDeleteLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductTypeDeleteLogic {
	return &ProductTypeDeleteLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductTypeDeleteLogic) ProductTypeDelete(req *types.ProductTypeDeleteRequest) (resp *types.ProductTypeDeleteResponse, err error) {
	item := model.ProductType{}
	err = l.svcCtx.DB.Where("id = ?", req.Id).First(&item).Error
	if err != nil {
		return nil, err
	}
	err = l.svcCtx.DB.Where("id = ?", req.Id).Delete(&model.ProductType{}).Error
	if err != nil {
		return nil, err
	}
	resp = &types.ProductTypeDeleteResponse{
		Id: req.Id,
	}
	return
}
